package edu.uwm.capstone.diasmart;

import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.view.MenuItem;
import edu.uwm.capstone.diasmart.types.EntryTypeFactory;

public class EditPreferencesActivity extends PreferenceActivity {

	@SuppressWarnings("deprecation")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);
		getPreferenceScreen();
		PreferenceScreen preferenceScreen = getPreferenceManager()
				.createPreferenceScreen(this);
		getPreferenceScreen().addPreference(preferenceScreen);
		preferenceScreen.setTitle(R.string.global_types);
		preferenceScreen.setSummary(R.string.select_global_types);

		for (int i = 0; i < EntryTypeFactory.TYPE_LIST.length; i++) {
			CheckBoxPreference typeCheckBox = new CheckBoxPreference(
					this);
			int j = EntryTypeFactory.TYPE_LIST[i];
			typeCheckBox.setTitle(EntryTypeFactory.getTypeString(j));
			typeCheckBox
					.setKey(getString(R.string.global_view_type_key_prefix) + j);
			typeCheckBox.setDefaultValue(Boolean.TRUE);
			preferenceScreen.addPreference(typeCheckBox);
		}
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 0:
			startActivity(new Intent(this, EditPreferencesActivity.class));
			return true;
		}
		return false;
	}

}
